package userModel

import (
	"arabApi/app/api/models"
	"arabApi/pkg/database"
	"fmt"
)

// User 用户模型
type User struct {
	models.BaseModel

	Name     string `json:"name,omitempty"`
	Email    string `json:"email,omitempty"`
	Phone    string `json:"-"`
	Password string `json:"-"`

	models.CommonTimestampsField
}

// model 查询数据库 只查数据。不做判断和处理

func IsPhoneExist(phone string) bool {
	var count int64
	fmt.Println("this", phone)
	database.DB.Model(User{}).Where("name = ?", phone).Count(&count)
	return count > 0
}

func Login(name string) User {
	var user User
	database.DB.Model(User{}).Where("name = ?", name).Find(&user)
	return user
}

func Sel() []User {
	user1 := make([]User, 0)
	database.DB.Model(User{}).Find(&user1)
	return user1
}

func UserMsg(id int64) User {
	var user User
	database.DB.Model(User{}).Where("id = ?", id).Find(&user)
	return user
}

func UserList() []User {
	var user []User
	database.DB.Model(User{}).Find(&user)
	return user
}
